package com.irain.pp.tool.mybatis.dto;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @author iRain
 * @date 2017/12/19 20:24
 */
public class Statistic {

    private Map<String,BigDecimal> sumMap = new HashMap<>();

    private Long count;

    public void putSum(String property, BigDecimal sum){
        if (sum == null) {
            sumMap.put(property, BigDecimal.ZERO);
        } else {
            sumMap.put(property, sum);
        }
    }

    public BigDecimal getSum(String property){
        BigDecimal sum = sumMap.get(property);
        if (sum == null){
            throw new NullPointerException();
        }
        return sum;
    }

    public Long getCount() {
        return count;
    }

    public void setCount(Long count) {
        this.count = count;
    }

    @Override
    public String toString() {
        return "Statistic{" +
                "sumMap=" + sumMap +
                ", count=" + count +
                '}';
    }
}
